#!/bin/sh

set -ex

src="${1}" # e.g. /swapfile4
shift 1
size="${1}" # e.g. 10G
shift 1

set -ex

# fail if swapfile exists.
[ ! -f "${src}" ]

sudo fallocate -l "${size}" "${src}"
sudo mkswap "${src}"
sudo chown root:root "${src}"
sudo chmod 600 "${src}"
sudo swapon "${src}"
